package userimage.page;

import javax.swing.*;

import java.awt.*;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;

import static global.ProjectData.*;

public class Page extends JPanel implements ComponentListener {

    private JPanel userArea = new JPanel();
    private PageTopBar topBar = new PageTopBar();

    public Page(int x, int y, int width, int height) {
        super();
        setBackground(theme.pagebg);
        setBounds(x, y, width, height);
        setLayout(null);
        addComponentListener(this);

        topBar.setBackground(theme.pagebg);

        add(userArea);
        add(topBar);
    }

    public JPanel getUserArea() {
        return userArea;
    }

    public void setUserArea(JPanel area) {
        area.setLocation(userArea.getLocation());
        area.setSize(userArea.getSize());
        remove(userArea);
        userArea = area;
        add(userArea);
    }

    @Override
    public void componentResized(ComponentEvent componentEvent) {
        topBar.setSize(getWidth(), theme.pagetopbar_height);
        topBar.setLocation(0, 0);

        userArea.setSize(getWidth(), getHeight() - theme.pagetopbar_height);
        userArea.setLocation(0, theme.pagetopbar_height);
    }

    @Override
    public void componentMoved(ComponentEvent componentEvent) {

    }

    @Override
    public void componentShown(ComponentEvent componentEvent) {

    }

    @Override
    public void componentHidden(ComponentEvent componentEvent) {

    }

}
